<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->

@section('content')
    <link rel="stylesheet" href="/static/admin/libs/layui/mods/extend/step/step.css" />
    <style>.layui-card-body{overflow-y: scroll;}</style>
    <div id="demo0"></div>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>代理商编号
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="store_sn" value="{{ $data['store_sn'] }}" class="layui-input layui-disabled">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>代理商名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="store_name" lay-verify="required" lay-reqtext="必填项,请填写信息" value="{{ $data['store_name'] }}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>所属子公司</label>
                    <div class="layui-input-inline">
                        <select name="subsidiary" lay-verify="required" lay-reqtext="请选择所属子公司">
                            <option value="">请选择</option>
                            <option value="上海有利康商贸有限公司" @if(isset($data['subsidiary']) && $data['subsidiary']=='上海有利康商贸有限公司') selected @endif>上海有利康商贸有限公司</option>
                            <option value="亿恩鑫（上海）生物科技有限公司" @if(isset($data['subsidiary']) && $data['subsidiary']=='亿恩鑫（上海）生物科技有限公司') selected @endif>亿恩鑫（上海）生物科技有限公司</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><b>个人信息：</b></label>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">法人身份证</label>
                    <div class="layui-input-inline layui-upload">
                        <button type="button" class="layui-btn" id="aa1">上传身份证人像面</button>
                        <div class="layui-upload-list">
                            <input name="principal_card_a" value="{{ $data['principal_card_a'] }}" id="vv1" type="hidden">
                            <img class="layui-upload-img" src="{{ $data['principal_card_a'] }}" id="dd1" width="150px" height="100px" >
                        </div>
                    </div>
                    <div class="layui-input-inline layui-upload">
                        <button type="button" class="layui-btn" id="aa2">上传身份证国徽面</button>
                        <div class="layui-upload-list">
                            <input name="principal_card_b" value="{{ $data['principal_card_b'] }}" id="vv2" type="hidden">
                            <img class="layui-upload-img" src="{{ $data['principal_card_b'] }}" id="dd2" width="150px" height="100px" >
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="principal_name" lay-verify="required" lay-reqtext="必填项,请填写信息"  value="{{ $data['principal_name'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">电话</label>
                        <div class="layui-input-inline">
                            <input type="text" name="principal_mobile" lay-verify="required" lay-reqtext="必填项,请填写信息"  value="{{ $data['principal_mobile'] }}"  class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">邮件</label>
                        <div class="layui-input-inline">
                            <input type="text" name="principal_email" value="{{ $data['principal_email'] }}"  class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">地址</label>
                        <div class="layui-input-inline">
                            <input type="text" name="principal_address"  value="{{ $data['principal_address'] }}"  class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">身份证号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="principal_card_sn" lay-verify="required" lay-reqtext="必填项,请填写信息"  value="{{ $data['principal_card_sn'] }}"  class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><b>公司资料：</b></label>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">企业证件</label>
                    <div class="layui-input-inline layui-upload">
                        <button type="button" class="layui-btn" id="aa3">上传营业执照</button>
                        <div class="layui-upload-list">
                            <input name="company_license" value="{{ $data['company_license'] }}" id="vv3" type="hidden">
                            <img class="layui-upload-img" src="{{ $data['company_license'] }}" id="dd3" width="150px" height="100px">
                        </div>
                    </div>
                    <div class="layui-input-inline layui-upload">
                        <button type="button" class="layui-btn" id="aa4">上传营运许可证</button>
                        <div class="layui-upload-list">
                            <input name="company_license_yy" value="{{ $data['company_license_yy'] }}" id="vv4" type="hidden">
                            <img class="layui-upload-img" src="{{ $data['company_license_yy'] }}" id="dd4" width="150px" height="100px">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">公司名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="company_name" value="{{ $data['company_name'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">注册号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="company_sn" lay-verify="required" lay-reqtext="必填项,请填写信息"  value="{{ $data['company_sn'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">公司性质</label>
                        <div class="layui-input-inline">
                            <input type="text" name="company_type" value="{{ $data['company_type'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">公司地址</label>
                        <div class="layui-input-inline">
                            <input type="text" name="company_addrss" value="{{ $data['company_addrss'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">法人代表</label>
                        <div class="layui-input-inline">
                            <input type="text" name="company_corporation" value="{{ $data['company_corporation'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">注册资本</label>
                        <div class="layui-input-inline">
                            <input type="text" name="company_registered_capital" value="{{ $data['company_registered_capital'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">成立日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="company_create_time" value="{{ $data['company_create_time'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">营业期限</label>
                        <div class="layui-input-inline">
                            <input type="text" name="company_operating_period" value="{{ $data['company_operating_period'] }}" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-block">
                        <label class="layui-form-label">经营范围</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" class="layui-textarea" name="company_business_scope" >{{ $data['company_business_scope'] }}</textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">折扣率</label>
                        <div class="layui-input-inline">
                            <input type="number" name="discount_rate" value="{{ $data['discount_rate'] }}" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline" pane="">
                        <label class="layui-form-label">是否补货</label>
                        <div class="layui-input-block">
                            <input type="checkbox" @if($data['is_replenishment'] == 1) checked="" @endif value="1" name="is_replenishment" lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline" pane="">
                        <label class="layui-form-label">运费收取</label>
                        <div class="layui-input-block">
                            <input type="checkbox" @if($data['is_express_fee'] == 1) checked="" @endif value="1" name="is_express_fee" lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline" pane="">
                        <label class="layui-form-label">一件代发</label>
                        <div class="layui-input-block">
                            <input type="checkbox" @if($data['is_agent'] == 1) checked="" @endif  name="is_agent" value="1" lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">资质期限</label>
                        <div class="layui-input-inline">
                            <input type="text" name="agent_start_time" placeholder="开始日" id="start" value="{{ $data['agent_start_time'] }}" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="agent_end_time" placeholder="结束日" id="end" value="{{ $data['agent_end_time'] }}" class="layui-input">
                        </div>
                    </div>
                </div>

                <!-- 新增的免审核设置字段 -->
                <div class="layui-form-item">
                    <label class="layui-form-label"><b>免审核设置：</b></label>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">允许一定金额内免审核</label>
                        <div class="layui-input-inline">
                            <input type="number" name="avoid_review_amount" value="{{ $data['avoid_review_amount'] ?? 0 }}"
                                   lay-verify="number" min="0" step="0.01" class="layui-input"
                                   placeholder="请输入大于0的金额">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">免审核时段</label>
                        <div class="layui-input-inline">
                            <input type="text" name="avoid_review_start_time" id="avoid_review_start_time"
                                   placeholder="开始日期时间" autocomplete="off" class="layui-input"
                                   value="{{ isset($data['avoid_review_start_time']) ? $data['avoid_review_start_time'] : '' }}">
                        </div>
                        <div class="layui-form-mid">至</div>
                        <div class="layui-input-inline">
                            <input type="text" name="avoid_review_end_time" id="avoid_review_end_time"
                                   placeholder="结束日期时间" autocomplete="off" class="layui-input"
                                   value="{{ isset($data['avoid_review_end_time']) ? $data['avoid_review_end_time'] : '' }}">
                        </div>
                    </div>
                </div>



                <div class="layui-form-item">
                    <div class="layui-block">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" class="layui-textarea" name="remark" >{{ $data['remark'] }}</textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-block">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <select name="status" lay-verify="required">
                                @foreach($statusList as $kk => $item)
                                    @if( $kk==$data['status'])
                                        <option value="{{ $kk }}" selected>{{ $item }}</option>
                                    @else
                                        <option value="{{ $kk }}">{{ $item }}</option>
                                    @endif
                                @endforeach
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <input type="hidden" value="{{ $data['id'] }}" name="id">
                    <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
                </div>
            </form>
        </div>
    </div>
    <script>
        layui.use('upload', function() {
            var $ = layui.jquery, upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#aa1'
                , url: '/admin/index/imageUpload' //改成您自己的上传接口
                , headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#dd1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == 1) {
                        $('#vv1').val(res.data.image);
                    } else {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                }
            });
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#aa2'
                , url: '/admin/index/imageUpload' //改成您自己的上传接口
                , headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#dd2').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == 1) {
                        $('#vv2').val(res.data.image);
                    } else {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                }
            });
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#aa3'
                , url: '/admin/index/imageUpload' //改成您自己的上传接口
                , headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#dd3').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == 1) {
                        $('#vv3').val(res.data.image);
                    } else {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                }
            });
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#aa4'
                , url: '/admin/index/imageUpload' //改成您自己的上传接口
                , headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#dd4').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == 1) {
                        $('#vv4').val(res.data.image);
                    } else {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                }
            });
        });
        layui.use(['form','layer','jquery'], function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(add)', function(data) {
                console.log(data);
                //发异步，把数据提交给php
                $.ajax({
                    type: 'POST',
                    url: '/admin/store/storeEdit',
                    data: data.field,
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        layer.alert(data.msg)
                        if (data.code == 1) {
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        }
                    },
                    error: function (xhr, type) {
                        alert('Ajax error!')
                    }
                });

                return false;
            });

        });
    </script>
    <script>
        layui.use('laydate',
            function () {
                var laydate = layui.laydate;

                //执行一个laydate实例
                laydate.render({
                    elem: '#start', //指定元素
                    type: 'datetime'
                });

                //执行一个laydate实例
                laydate.render({
                    elem: '#end', //指定元素
                    type: 'datetime'
                });
            });
        layui.config({
            base: 'layui/mods/extend/step/'
        }).use('step',function(){
            var step = layui.step

                ,data0 = {
                steps: [{"title" : "提交初审", "time" : "2018-07-22"},
                    {"title" : "初审完成", "time" : "2018-07-22"},
                    {"title" : "提交复审", "time" : "2018-07-22"},
                    {"title" : "复审完成", "time" : "2018-07-22"},
                    {"title" : "处理完成", "time" : "2018-07-22"}]
                ,current: 0
            }

            step.ready({
                elem: '#demo0',
                data: data0,
                width: '150px',
                color: {
                    success:'#56ece3',
                    error:'#848484'
                }
            })
        })

    </script>
    <script>
        layui.use(['laydate', 'jquery'], function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;

            // 格式化日期时间函数（Y-m-d H:i:s）
            function formatDateTime(date, isEndOfDay = false) {
                var y = date.getFullYear();
                var m = (date.getMonth() + 1).toString().padStart(2, '0');
                var d = date.getDate().toString().padStart(2, '0');
                var hh = isEndOfDay ? '23' : '00';
                var mm = isEndOfDay ? '59' : '00';
                var ss = isEndOfDay ? '59' : '00';
                return y + '-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss;
            }

            // 获取当前时间作为默认值
            var today = new Date();
            var nextWeek = new Date();
            nextWeek.setDate(today.getDate() + 7);

            // 默认开始时间（今天 00:00:00）
            var defaultStartDate = formatDateTime(today);
            // 默认结束时间（7天后 23:59:59）
            var defaultEndDate = formatDateTime(nextWeek, true);

            // 从 input 中获取值，优先使用后台数据
            var startDateValue = $('#avoid_review_start_time').val();
            var endDateValue = $('#avoid_review_end_time').val();

            // 如果后台数据为空，则使用默认值
            if (!startDateValue) {
                startDateValue = defaultStartDate;
                $('#avoid_review_start_time').val(startDateValue);
            }
            if (!endDateValue) {
                endDateValue = defaultEndDate;
                $('#avoid_review_end_time').val(endDateValue);
            }

            // 开始日期时间选择器
            var startDatePicker = laydate.render({
                elem: '#avoid_review_start_time',
                type: 'datetime',  // 关键修改：使用日期时间选择器
                format: 'yyyy-MM-dd HH:mm:ss',  // 关键修改：完整时间格式
                theme: '#448AFF',
                max: endDateValue,
                value: startDateValue,
                ready: function () {
                    this.elemItem.querySelector('.layui-laydate-content').style.width = '180px';
                },
                change: function (value, date) {
                    if (date) {
                        endDatePicker.config.min = value;
                        endDatePicker.render();
                    }
                }
            });

            // 结束日期时间选择器
            var endDatePicker = laydate.render({
                elem: '#avoid_review_end_time',
                type: 'datetime',  // 关键修改：使用日期时间选择器
                format: 'yyyy-MM-dd HH:mm:ss',  // 关键修改：完整时间格式
                theme: '#448AFF',
                min: startDateValue,
                value: endDateValue,
                ready: function () {
                    this.elemItem.querySelector('.layui-laydate-content').style.width = '180px';
                },
                change: function (value, date) {
                    if (date) {
                        startDatePicker.config.max = value;
                        startDatePicker.render();
                    }
                }
            });
        });
    </script>
@endsection